<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>使用 layDate 独立版</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">

  <style>
  body{padding: 20px;}
  .demo-input{padding-left: 10px; height: 38px; min-width: 262px; line-height: 38px; border: 1px solid #e6e6e6;  background-color: #fff;  border-radius: 2px;}
  .demo-footer{padding: 50px 0; color: #999; font-size: 14px;}
  .demo-footer a{padding: 0 5px; color: #01AAED;}

  .select{
    width: 312px;
    overflow: hidden;
    margin-top: 20px;
    border: 1px solid #DDD;
    display: block;
  }

  .select span{
    height: 30px;
    width: 40px;
    display: block;
    float: left;
    font-size: 14px;
    line-height: 30px;
    text-align: center;
    border: 1px solid #DDD;
    box-sizing: border-box;
    margin-right: -1px;
    margin-top: -1px;
    cursor: pointer;
  }

  .SelectWeekBox {
    position: relative;
  }

  .SelectWeekBox .select{
    background: #fdfdfd;
    position: absolute;
    left: 0px;
    top: 9px;
  }


  </style>
</head>
<body>
<input type="text" class="demo-input" placeholder="请选择年份" id="SelectYear">

<span id="SelectWeekBox" class="SelectWeekBox">
  <input type="text" class="demo-input" placeholder="请选择周" id="SelectWeek">
  <span class="select"></span>
</span>





<script src="js/jquery-1.10.2.js"></script> 

<script src="laydate/laydate.js"></script> 

<script>

// 满足鼠标移动到周上，显示开始时间和结束时间
// 满足可以设置周的开始时间


laydate.render({
  elem: '#SelectYear'
  ,type: 'year'
  ,done:function(date){
      console.log(date);
      var NumOfWeeks = getNumOfWeeks(date);
      var spanDom ="";

      for(var i = 1;i<=NumOfWeeks;i++){
        spanDom +='<span title="2011-11-12到2011-12-13">'+(i<9?'0'+i:i)+'周</span>';
      }

      console.log(spanDom);
      $('.select').children().remove();
      $('.select').html(spanDom);
       $('.select span').on('click',function(event) {
         /* Act on the event */
         $("#SelectWeek").val($(this).text());
       });
  }
});


function getNumOfWeeks(year){
  var d=new Date(year,0,1);
  console.log(d);
  var yt=( ( year%4==0 && year%100!=0) || year%400==0)?366:365; 
  return Math.ceil((yt-d.getDay())/7.0);
}



 
//document.write("2017年有"+getNumOfWeeks(2017)+"周");
//var NumOfWeeks = getNumOfWeeks(2017);
// console.log(spanDom);



function getInfo(year, month) {
       var getInfo = function (year, month) {
                var d = new Date();
                d.setFullYear(year, month - 1, 1);
                var w1 = d.getDay();
                if (w1 == 0) w1 = 7;
                d.setFullYear(year, month, 0);
                var dd = d.getDate();
                if (w1 != 1) {
                    var d1 = 7 - w1 + 2;
                } else {
                    d1 = 1;
                }
                var week_count = Math.ceil((dd - d1 + 1) / 7);
                for (var i = 0; i < week_count; i++) {
                    var monday = d1 + i * 7;
                    var sunday = monday + 6;
 
　　　　　　　　　　　　 if (monday < 10) {
                        monday = (Array(2).join(0) + monday).slice(-2);
                    }
                    if (sunday < 10) {
                        sunday = (Array(2).join(0) + sunday).slice(-2);
                    }//此处是为了获取的日期中的日如果小10前边的0会自动消失的处理
                    var from = year + "/" + month + "/" + monday;
                    var to;
                    if (sunday <= dd) {
                        to = year + "/" + month + "/" + sunday;
                    } else {
                        d.setFullYear(year, month - 1, sunday);
                        to = d.getFullYear() + "/" + (d.getMonth() + 1) + "/" + d.getDate();
                    }
                    var d11 = new Date(year + "-" + month + "-" + monday);
                    var d2 = new Date(year + "-" + month + "-" + monday);
                    d2.setMonth(0);
                    d2.setDate(1);
                    var rq = d11 - d2;
                    var s1 = Math.ceil(rq / (24 * 60 * 60 * 1000));
                    var s2 = Math.ceil(s1 / 7);
                   console.log("第" + s2 + "周(" + from + " 到 " + to + ")"
                    );
                }
            };
    }
    getInfo('2013','12');



</script>
</body>
</html>